/**
 * @description 邮寄信件
 */

interface ILetterProcess {
  /**
   * @description 写内容
   * @param ctx 
   */
  writeContext(ctx: string): void
  /**
   * @description 写信封地址
   * @param address 
   */
  fillEnvelope(address: string): void

  /**
   * @description 信放到信封里
   */
  letterIntoEnvelope(): void

  /**
   * @description 邮寄出去
   */
  sendLetter(): void
}
/**
 * @description 子系统角色
 */
class LetterProcess implements ILetterProcess {
  writeContext(ctx: string): void {
    console.log('写内容：' + ctx);
  }
  fillEnvelope(address: string): void {
    console.log('写信封地址：' + address);
  }
  letterIntoEnvelope(): void {
    console.log('信放到信封里');
  }
  sendLetter(): void {
    console.log('邮寄出去')
  }
  policeCheck(): void {
    console.log('警察检查好')
  }
}

/**
 * @description 门面角色
 */
class ModernPostOffice {
  _letterProcess: LetterProcess
  constructor(letterProcess: LetterProcess) {
    this._letterProcess = letterProcess
  }

  sendLetter(ctx: string, address: string) {
    this._letterProcess.writeContext(ctx)
    this._letterProcess.fillEnvelope(address)
    this._letterProcess.letterIntoEnvelope()
    this._letterProcess.policeCheck()
    this._letterProcess.sendLetter()
  }
}

function main() {
  const _letterProcess = new LetterProcess()
  const _modernPostOffice = new ModernPostOffice(_letterProcess)
  _modernPostOffice.sendLetter('今天星期一', '星期二')
}
main()